package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;


    /**
     * 今日佳人
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询分页好友推荐列表
     * @param dto
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto){
        PageResult pr = tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pr);
    }

    /**
     * 查询佳人详情
     * @param userId
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId){
        TodayBest best = tanhuaService.findPersonalInfo(userId);
        return ResponseEntity.ok(best);
    }

    /**
     * 查看陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String contents = tanhuaService.findStrangerQuestions(userId);
        return ResponseEntity.ok(contents);
    }

    /**
     * 回复陌生人问题,发送好友请求
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map){
        // 从前端传递过来的是userID是Integer类型的,需要转化一下
        Long userId = Long.valueOf(map.get("userId").toString());
        String reply = map.get("reply").toString();
        tanhuaService.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     *  探花,左滑右滑 -- 查询推荐用户列表
     */
    @GetMapping("/cards")
    public ResponseEntity queryCardsList(){
        List<TodayBest> list = tanhuaService.queryCardsList();
        return ResponseEntity.ok(list);
    }

    /**
     *  探花 -- 右滑喜欢功能
     */
    @GetMapping("/{id}/love")
    public ResponseEntity likeUser(@PathVariable("id") Long likeUserId){
        tanhuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     *  探花 -- 左滑不喜欢功能
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity notLikeUser(@PathVariable("id") Long likeUserId){
        tanhuaService.notLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     *  搜索附近的人
     */
    @GetMapping("/search")                              // 性别                                   默认值;两千米    距离
    public ResponseEntity<List<NearUserVo>> queryNearUser(String gender,@RequestParam(defaultValue = "2000") String distance){
        List<NearUserVo> list = tanhuaService.queryNearUser(gender,distance);
        return ResponseEntity.ok(list);
    }
}
